package br.edu.unifei.mestrado.grafo;

import br.edu.unifei.mestrado.commons.graph.NodeWrapper;
import br.edu.unifei.mestrado.commons.graph.RelationshipWrapper;
import br.edu.unifei.mestrado.db.graph.GraphDB;
import edu.uci.ics.jung.graph.UndirectedSparseGraph;

public class GrafoNeoDBView extends GraphDB {

	private UndirectedSparseGraph<NodeWrapper, RelationshipWrapper> grafo;

	public GrafoNeoDBView(String dbFileName, Integer level) {
		super(true, dbFileName, level);
		grafo = new UndirectedSparseGraph<NodeWrapper, RelationshipWrapper>();
	}

	//UTIL: o GrafoNeoDBView precisa converter o grafo do banco para o grafo em UndirectedSparseGraph
	//UTIL: converte o grafo em banco GraphDB<Node, Relationship> para UndirectedSparseGraph<nodeWrapper, relationshipWrapper>
	@Override
	public void readGraph() {
		super.readGraph();

		for (NodeWrapper node : getAllNodes()) {
			grafo.addVertex(node);
		}
		// pega as arestas e nós do banco e joga na memoria
		for (RelationshipWrapper rel : getAllEdges()) {
			// Adiciona a aresta, e esse médodo já adiciona os nós se não existir
			grafo.addEdge(rel, rel.getStartNode(), rel.getEndNode());
		}
	}

	public UndirectedSparseGraph<NodeWrapper, RelationshipWrapper> getGraphToView() {
		return grafo;
	}
}
